# !/usr/bin/python3
# -*- coding: utf-8 -*-

import requests
from bs4 import BeautifulSoup


def main(page):
    url = 'https://movie.douban.com/top250?start=' + str(page * 25) + '&filter='
    html = request_douban(url)
    soup = BeautifulSoup(html, 'lxml')
    list = soup.find(class_='grid_view').findAll('li')
    for item in list:
        # print(item)
        # print('---------------->>>>>>>>>>>------------')
        item_name = item.find(class_='title').string
        item_img = item.find('a').find('img').get('src')
        item_score = item.find(class_='rating_num').string
        item_index = item.find(class_='pic').find(class_='').string
        # item_author = item.find('p').text
        if item.find(class_='inq') is not None:
            item_intr = item.find(class_='inq').string
            print(item_index + ' | ' + item_name + ' | ' + item_img + ' | ' + item_score + ' | ' + item_intr)
        else:
            print(item_index + ' | ' + item_name + ' | ' + item_img + ' | ' + item_score)


def request_douban(url):
    try:
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                          'Chrome/79.0.3945.88 Safari/537.36'}
        response = requests.get(url, headers=headers)
        if response.status_code == 200:
            return response.text
    except requests.RequestException:
        return None


if __name__ == '__main__':
    for i in range(0, 10):
        main(i)
